package com.wva.captcha.config;

import com.wva.captcha.enums.QueueEnum;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: hong
 * @Date: 2025/2/3 23:14:37
 */
@Configuration
public class MQConfig {

    /**
     * 短信验证码发送队列绑定的交换机
     * @return
     */
    @Bean
    TopicExchange smsTopic() {
        return new TopicExchange(QueueEnum.SMS_CAPTCHA_SEND.getExchange());
    }

    /**
     * 短信验证码发送队列
     * @return
     */
    @Bean
    Queue smsSendQueue() {
        return new Queue(QueueEnum.SMS_CAPTCHA_SEND.getQueue());
    }

    /**
     * 短信验证码发送队列绑定到交换机
     * @param smsSendQueue
     * @param smsTopic
     * @return
     */
    @Bean
    Binding smsSendQueueBinding(Queue smsSendQueue, TopicExchange smsTopic) {
        return BindingBuilder
                .bind(smsSendQueue)
                .to(smsTopic)
                .with(QueueEnum.SMS_CAPTCHA_SEND.getRoutingKey());
    }
}
